﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.DotNet.MSIdentity.Shared;
using Newtonsoft.Json;
using System.Text.Json;
using System.Xml.Linq;
using WMSUIMVC.DTO.Finance;
using XuanKeZz.Application.HTTP;

namespace WMSUIMVC.Controllers
{
    /// <summary>
    /// 财务类别控制器
    /// </summary>
    public class FinanceController : Controller
    {
        private readonly IConfiguration _configuration;

        public FinanceController(IConfiguration configuration)
        {
            _configuration = configuration;
        }


        #region 财务类别

        public IActionResult FinanceType()
        {
            return View();
        }
        /// <summary>
        /// 显示财务类别
        /// 调用网关获取数据
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<IActionResult> GetFinanceType(SelectFinanceDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"]+"ywd/api/FinanceType/GetFinanceType?FinanceTypeName=" + dto.FinanceTypeName;
            //string url = "https://localhost:44381/api/FinanceType/GetFinanceType?FinanceTypeName="+FinanceTypeName;
            string GetFinance = await client.GetAsync(url);
            return Json(GetFinance);
        }
        /// <summary>
        /// 反填财务类别
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<IActionResult> FanFinanceType(FanFinanceDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "ywd/api/FinanceType/FanFinanceType?id=" + dto.id;
            //string url = "https://localhost:44381/api/FinanceType/FanFinanceType?id=" + id;
            string GetFinance = await client.GetAsync(url);
            return Json(GetFinance);
        }
        /// <summary>
        /// 修改财务类别
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<IActionResult> UpdFinanceType(AddFinanceDTO dto)
         {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "ywx/api/FinanceType/UpdFinanceType";
            //string url = "https://localhost:44335/api/FinanceType/UpdFinanceType";

            string list = JsonConvert.SerializeObject(dto);
            
            string GetFinance = await client.PutAsync(url,list);
            return Json(GetFinance);
        }
        /// <summary>
        /// 删除财务类别
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<IActionResult> DelFinanceType(DelFinanceDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "ywx/api/FinanceType/DelFinanceType";
            string list = JsonConvert.SerializeObject(dto);
            string GetFinance = await client.PostAsync(url,list);
            return Json(GetFinance);
        }
        /// <summary>
        /// 添加财务类别
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<IActionResult> AddFinanceType(AddFinanceDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "ywx/api/FinanceType/AddFinanceType";
            //string url = "https://localhost:44335/api/FinanceType/AddFinanceType";
            string list = JsonConvert.SerializeObject(dto);

            string GetFinance = await client.PostAsync(url, list);
            return Json(GetFinance);
        }


        /// <summary>
        /// 导出财务类别
        /// 调用网关获取数据
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<IActionResult> GetDaoFinanceType(SelectFinanceDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "ywd/api/FinanceType/GetFinanceType?GetFinanceDao=" + dto.FinanceTypeName;
            string GetFinance = await client.GetAsync(url);
            return Json(GetFinance);
        }


        #endregion

        #region 财务应收

        /////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////
        //////////////////////////////////财务应收///////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////
        /////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// 财务应收类别
        /// </summary>
        /// <returns></returns>
        public IActionResult FinancialReceivables()
        {
            return View();
        }
        /// <summary>
        /// 显示财务类别
        /// 调用网关获取数据
        /// </summary>
        /// <param name="Token"></param>
        /// <returns></returns>
        public async Task<IActionResult> GetFinancialReceivable(SelectReceivableDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "ywd/api/FinanceType/GetReceivablepage?pageindex=" + dto.PageIndex + "&pagesize=" + dto.PageSize + "&SerialNumber=" + dto.SerialNumber + "&ReceivableName=" + dto.ReceivableName + "&FinanceTypeId=" + dto.FinanceTypeId + "&Payer=" + dto.Payer + "&Kdate=" + dto.Kdate + "&Sdate=" + dto.Sdate + "&ReceivableState=" + dto.ReceivableState + "&Office_Id=" + dto.Office_Id + "&User_Id=" +dto.User_Id;
            string GetFinance = await client.GetAsync(url);
            return Json(GetFinance);
        }
        /// <summary>
        /// 添加财务应收
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<IActionResult> AddFinanceReceivable(AddFinanceReceivableDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "ywx/api/FinanceType/AddNewPaid";
            //string url = "https://localhost:44335/api/FinanceType/AddFinanceType";
            string list = JsonConvert.SerializeObject(dto);

            string GetFinance = await client.PostAsync(url, list);
            return Json(GetFinance);
        }
        /// <summary>
        /// 删除财务应收
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<IActionResult> DelFinanceReces(DelFinanceReceDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "ywx/api/FinanceType/DelNewPaid";
            string list = JsonConvert.SerializeObject(dto);
            string GetFinance = await client.PostAsync(url, list);
            return Json(GetFinance);
        }
        /// <summary>
        /// 反填财务应收
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<IActionResult> FanFinanceRece(FanFinanceReceDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "ywd/api/FinanceType/FanNewPaid?id=" + dto.id;
            //string url = "https://localhost:44381/api/FinanceType/FanFinanceType?id=" + id;
            string GetFinance = await client.GetAsync(url);
            return Json(GetFinance);
        }
        /// <summary>
        /// 修改财务应收
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<IActionResult> UpdFinanceReceType(updReceDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "ywx/api/FinanceType/UpdNewPaid";
            //string url = "https://localhost:44335/api/FinanceType/UpdNewPaid";

            string list = JsonConvert.SerializeObject(dto);

            string GetFinance = await client.PutAsync(url, list);
            return Json(GetFinance);
        }
        /// <summary>
        /// 添加财务实收
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<IActionResult> AddFinancePay(AddFinancePayDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "ywx/api/FinanceType/AddPay";
            //string url = "https://localhost:44335/api/FinanceType/AddPay";
            string list = JsonConvert.SerializeObject(dto);

            string GetFinance = await client.PostAsync(url, list);
            return Json(GetFinance);
        }

        #endregion


    }
}
